package com.warmlight.voicepacket.ui.communitylm.widget;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.warmlight.voicepacket.R;

/**
 * 回复框基础框，固定于列表底部
 */
public class ReplyBarBase extends RelativeLayout {

    private ReplyBarBaseClickListener replyBarBaseClickListener;
    private ImageView iv_img;
    private TextView tv_reply;

    public interface ReplyBarBaseClickListener{
        void clickText();
        void clickImg();
    }

    /**
     * 设置点击监听
     * @param replyBarBaseClickListener
     */
    public void setOnReplyBarBaseClickListener(ReplyBarBaseClickListener replyBarBaseClickListener){
        this.replyBarBaseClickListener = replyBarBaseClickListener;
    }

    public ReplyBarBase(Context context) {
        super(context);
        initView(context);
    }

    public ReplyBarBase(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public ReplyBarBase(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    public void setBackground(boolean isTrans){
        if (isTrans){
            setBackgroundResource(R.color.transparent);
            tv_reply.setBackgroundResource(R.drawable.shape_input_trans);
            findViewById(R.id.tv_top).setBackgroundResource(R.color.Affffff);
            iv_img.setImageResource(R.drawable.icon_reply_base_img_trans);
            tv_reply.setTextColor(Color.parseColor("#80ffffff"));
        }else{
            setBackgroundResource(R.color.white);
            tv_reply.setBackgroundResource(R.drawable.shape_input);
            findViewById(R.id.tv_top).setBackgroundResource(R.color.color_eeeeee);
            iv_img.setImageResource(R.drawable.icon_reply_base_img);
            tv_reply.setTextColor(Color.parseColor("#999999"));
        }
    }

    private void initView(Context context){
        LayoutInflater.from(context).inflate(R.layout.replay_bar_base,this,true);
        tv_reply = findViewById(R.id.tv_reply);
        iv_img = findViewById(R.id.iv_img);
        setBackground(false);
        tv_reply.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (replyBarBaseClickListener != null){
                    replyBarBaseClickListener.clickText();
                }
            }
        });

        iv_img.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (replyBarBaseClickListener != null){
                    replyBarBaseClickListener.clickImg();
                }
            }
        });
    }
}
